//Local Includes
#include "Weapon.h"

//SGD Wrapper includes
#include "../SGD Wrappers/CSGD_TextureManager.h"
#include "../SGD Wrappers/CSGD_EventSystem.h"
#include "../SGD Wrappers/CSGD_Direct3D.h"

Weapon::Weapon()
{
	m_eType = ENT_WEAPON;
	SetWidth(128);
	SetHeight(128);
}

Weapon::~Weapon()
{
	CSGD_EventSystem::GetInstance()->UnregisterClientAll(this);
}

//Updates image per frame
void Weapon::Update(float elapsed_time) {

	//Move image up and down slowly;

	//...Stuff...
}


//Displays image per frame
void Weapon::Render(){

	//Create image Rectangle
	RECT image_rect;

	switch (type){
	case BOW:
		image_rect.left = 384;
		image_rect.right = 512;
		image_rect.top = 128;
		image_rect.bottom = 256;
		break;
	case SWORD:
		image_rect = { 128, 256, 256, 384 };
		break;
	}

	//Draw image
	CSGD_TextureManager::GetInstance()->Draw(image_id, (int) GetPosX(), (int) GetPosY(), 1.0f, 1.0f, &image_rect);

	//Draw Debug Information
	if (debug){
		//Do Stuff...
	}
}


//Handles events
void Weapon::HandleEvent(CEvent* pEvent){
	//If debug event is thrown
	if (pEvent->GetEventID() == "DEBUG"){
		this->debug = !this->debug;
	}
}

//Initialized weapon based on type
void Weapon::Initialize(float position_x, float position_y, WeaponTypes type, bool debug){

	//Load appropriate weapon image
	switch (type)
	{
	case BOW:
		image_id = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/images/Player/Weapons/bb_recurvebow_sheet(resized).png"));
		break;
	case SWORD:
		image_id = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/images/Player/Weapons/bb_sabre_sheet_resize.png"));
		break;
	}
	//Set Weapon Type
	this->type = type;

	//Set Weapon Position
	SetPosX(position_x);
	SetPosY(position_y);

	//Set Debug mode
	this->debug = debug;

}
